home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / gui / pmdev.lha / PopupMenuDeveloper / Demos / TestMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-22  |  3.0 KB  |  108 lines

  1. //
  2. // $VER: TestMenu.c 1.0 (10.5.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <clib/intuition_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include <libraries/pm.h>
  23. #include <proto/pm.h>
  24.  
  25. struct IntuitionBase    *IntuitionBase;
  26. struct GfxBase        *GfxBase;
  27. struct PopupMenuBase    *PopupMenuBase;
  28.  
  29. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  30.             // The font in this window's rastport will be used for the menu.
  31.  
  32. void main()
  33. {
  34.     BOOL r=TRUE;
  35.     struct IntuiMessage *im,imsg;
  36.     struct PopupMenu *p;
  37.  
  38.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  39.     if(PopupMenuBase) {
  40.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  41.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  42.  
  43.         p=MakeMenu(    PMItem("Project"),
  44.                 PM_Sub, PMMenu("A small menu..."),    // Create a little menu...
  45.                     PMItem("New"),        PM_UserData,    1,    End,
  46.                     PMItem("Open..."),    PM_UserData,    2,    End,
  47.                     PMNarrowTitleBar,                End,
  48.                     PMItem("Save"),        PM_UserData,    3,    End,
  49.                     PMItem("Save as..."),    PM_UserData,    4,    End,
  50.                     PMNarrowTitleBar,                End,
  51.                     PMItem("About..."),    PM_UserData,    6,    End,
  52.                     PMNarrowTitleBar,                End,
  53.                     PMItem("Quit"),        PM_UserData,    5,    End,
  54.                     End,
  55.                 End,
  56.                 PMItem("Edit"),
  57.                 PM_Sub,    MakeMenu(
  58.                     PMItem("Cut"),    End,
  59.                     PMItem("Copy"),    End,
  60.                     PMItem("Paste"),End,
  61.                     End,
  62.                 End,
  63.                 PMItem("Settings"),
  64.                 PM_Sub,    MakeMenu(
  65.                     PMCheckItem("?", 1),    End,
  66.                     End,
  67.                 End,
  68.             End;
  69.  
  70.         if(p) {
  71.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  72.                     WA_RMBTrap,    TRUE,
  73.                     WA_DragBar,    TRUE,
  74.                     WA_Width,    150,
  75.                     WA_Height,    100,
  76.                     WA_Left,    0,
  77.                     WA_Top,        100,
  78.                     WA_Title,    "Menu Tester",
  79.                     WA_CloseGadget,    TRUE,
  80.                     TAG_DONE);
  81.             if(w) {
  82.                 while(r) {
  83.                     WaitPort(w->UserPort);                        // Wait for a message
  84.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  85.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  86.                         ReplyMsg((struct Message *)im);                // Reply the message
  87.  
  88.                         switch(imsg.Class) {
  89.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  90.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  91.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  92.                                         PM_Menu,        p,
  93.                                         PM_Code,        imsg.Code,
  94.                                         PM_PullDown,        TRUE,
  95.                                         TAG_DONE))-5);
  96.                                 printf("ReturnCode: %ld\n", r+5);
  97.                             break;
  98.                         }
  99.                     }
  100.                 }
  101.                 CloseWindow(w);
  102.             } else printf("Window error!\n");
  103.             PM_FreePopupMenu(p);
  104.         } else printf("Menu error!\n");
  105.         CloseLibrary((struct Library *)PopupMenuBase);
  106.     }
  107. }
  108.